{extend name="public/base" /}
{block name="content"}
<div class="x-nav">
    <a class="layui-btn layui-btn-primary layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:38px">ဂ</i></a>
</div>
<div class="x-body">
    <div class="layui-row">
        <div class="layui-form-item">
            <label class="layui-form-label">条件搜索：</label>
            <div class="layui-input-inline">
                <select id="condition" name="condition" lay-verify="required">
                    <option value="">请选择</option>
                    <option value="id">编号</option>
                    <option value="username">微信名</option>
                    <option value="start_time">开始时间</option>
                    <option value="end_time">结束时间</option>
                    <option value="time_count">小时数</option>
                    <option value="seat_number">座位号</option>
                    <option value="is_card">是否月卡</option>
                </select>
            </div>
            <div class="layui-inline">
                <input class="layui-input" name="content" id="content" autocomplete="off" placeholder="请输入搜索内容">
            </div>
            <button class="layui-btn layui-btn-normal" id="btnSearch"><i class="layui-icon">&#xe615;</i></button>
        </div>
    </div>
    <xblock>
        <button class="layui-btn layui-btn-normal" onclick="add()"><i class="layui-icon"></i>添加</button>显示当天预约信息
    </xblock>
    <table id="demo" lay-filter="test"></table>

    <!-- 行操作  -->
    <script type="text/html" id="operateBar">
        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit" id="ed">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>
</div>
{/block}
{block name="js"}
<script>
    layui.use('table', function(){
        var $ = layui.jquery;
        var table = layui.table;

        //第一个实例
        table.render({
            elem: '#demo'
            ,url: '{:url("admin/info/getDatas")}' //数据接口
            ,page: true //开启分页
            ,cols: [[ //表头
                {field: 'id', title: '编号', sort: true, fixed: 'left'}
                ,{field: 'username', title: '微信名',sort: true}
                ,{field: 'start_time', title: '开始时间', sort: true}
                ,{field: 'end_time', title: '结束时间',sort: true,}
                ,{field: 'time_count', title: '小时数',align: 'center',sort: true}
                ,{field: 'seat_number', title: '座位号',align: 'center',sort: true}
                ,{field: 'is_card', title: '是否月卡',align: 'center',sort: true}
                ,{fixed: 'right', title: '操作',sort: true,toolbar:'#operateBar'}
            ]]
            ,id: 'idTest' //搜索容器id
        });

        //搜索
        $('#btnSearch').click(function () {
            // layer.alert($('#condition').val()+$('#content').val());
            table.reload('idTest', {
                where: { //设定异步数据接口的额外参数，任意设
                    condition: $('#condition').val(),
                    content: $('#content').val()
                }
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });

        //添加书籍
        $('#infoAdd').click(function () {
            window.location.href = "{:url('admin/info/add')}";
        });

        //监听工具栏
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            console.log(obj);
            //编辑
            if (obj.event === 'edit') {
                var str = "{:url('admin/info/edit', ['id'=>'p_id'])}";
                var str1 = str.replace('p_id',data.id);
                window.location.href = str1;
            }
            //删除
            if (obj.event === 'del') {
                layer.confirm('确定要删除吗？',{
                    title: '提示',
                    icon: 3
                }, function (index) {
                    layer.close(index);

                    $.ajax({
                        url: "{:url('admin/info/del')}",
                        type: 'post',
                        data: {id: data.id},
                        dataType: 'json',
                        success: function (res) {
                            if (res.code == 1) {
                                layer.msg(res.msg, {
                                   icon: 6,
                                   time: 2000
                                }, function () {
                                    location.href = res.url;
                                });
                            }else {
                                layer.open({
                                    icon: 5,
                                    title: '提示',
                                    content: res.msg,
                                    anim: 6
                                });
                            }
                        }
                    });
                });
            }
        });

    });

    //添加
    function add() {
        window.location.href = "{:url('admin/info/add')}";
    }
</script>
{/block}